<?php

namespace App\Http\Controllers\web;

use app\api\model\article\Article;
use App\Http\Controllers\Controller;
use App\Models\Commission;
use App\Models\User;
use App\Repository\RepositoryInterface\PersonalInterface;
use Illuminate\Http\Request;
use think\Exception;

//个人主页
class PersonalController extends Controller
{
    //
    protected $personal;

    public function __construct(PersonalInterface $personal){
        $this->personal = $personal;
    }

    /**
     * @param Request $request
     * @return \think\response\Json|void
     * 个人中心页面
     */

    public function index(Request $request){
        $uid=$request->get('uid');
        return $this->personal->index($uid);
    }


    /***
     * @param Request $request
     * @return \think\response\Json|void
     * 佣金
     */
    public function commission(Request $request){
        try {
            $hid=$request->get('hid');
            $commission=Commission::leftjoin('user','commission.hid','user.uid')->get();
            $count=count($commission['incomeission']);
            return success('20000','查询成功',$count);
        }catch (\Exception $exception){
            return fail('500','查询失败','');
        }
    }



    /**
     * 团长新增方法
     */
    public function colonelCreate(Request $request){
        $pram=$request->post();
        return $this->personal->colonelCreate($pram);
    }


    /**
     * @return mixed
     * 社区活动列表
     */
    public function articleIndex(){

        return $this->personal->articleIndex();

    }

    /**
     * 用户订单
     */
    public function orderUser(Request $request){
        $uid=$request->get('uid');
        return $this->personal->orderUser($uid);

    }



    /**
     * @param Request $request
     * 活动新增
     */
    public function create(Request $request){
        try {
            $param=$request->get();
            $huo=Article::create($param);
            return success('20000','新增成功',$huo);
        }catch (\Exception $exception){
            return fail('500','新增失败','');
        }
    }





    public function listIn(){
        try {
            $list=Article::get();
            return success('20000','查询成功',$list);
        }catch (\Exception $exception){
            return fail('5000','查询失败','');
        }
    }
}
